package fr.greta.centreFormation.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import fr.greta.centreFormation.bean.Cursus;
import fr.greta.centreFormation.bean.Domaine;
import fr.greta.centreFormation.bean.Module;
import fr.greta.centreFormation.bean.UniteEnseignement;
import fr.greta.centreFormation.dao.Bdd;
import fr.greta.centreFormation.dao.CursusHome;
import fr.greta.centreFormation.dao.DomaineHome;
import fr.greta.centreFormation.dao.ModuleHome;
import fr.greta.centreFormation.dao.UniteEnseignementHome;

/**
 * Servlet implementation class ModifierUe
 */
public class ModifierUe extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ModifierUe() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		int idUe  = Integer.parseInt(request.getParameter("ue"));
		
		Bdd base = new Bdd();
		
		UniteEnseignement ueEnseignement = UniteEnseignementHome.selectUneUniteEnseignementById(idUe);
		
		HttpSession session = request.getSession(true);
		
		Hashtable<Integer, String> lesModule = new Hashtable<Integer, String>();
		
		for(Module m : ueEnseignement.getAllModule()){
			lesModule.put(m.getIdModule(), m.getIntituleModule());
		}
				
		session.setAttribute("laUE", ueEnseignement);
		session.setAttribute("lesModule", lesModule);
		session.setAttribute("idUe", idUe);
		
		ArrayList<Module> collectionModules = ModuleHome.selectAllModule();

		session.setAttribute("collectionModule", collectionModules);		
		session.setAttribute("idAction", 2);
		
		request.getRequestDispatcher("formulaireUE.jsp").forward(request, response);
		
		
	}

}
